package cn.javass.dp.memento.example4;


public class Operation implements OperationApi {

    private int result;

    @Override
    public int getResult() {
        return result;
    }

    @Override
    public void setResult(int result) {
        this.result = result;
    }

    @Override
    public void add(int opeNum) {
        result += opeNum;
    }

    @Override
    public void substract(int opeNum) {
        result -=opeNum;
    }

    @Override
    public Memento createMemento() {
        MementoImpl m = new MementoImpl(result);
        return m;
    }

    @Override
    public void setMemento(Memento memento) {
        MementoImpl memento1 = (MementoImpl) memento;
        this.result = memento1.getResult();
    }

    /**
     * 备忘录对象
     */
    private class MementoImpl implements Memento{
        private int result;
        public MementoImpl(int result) {
            this.result = result;
        }

        public int getResult() {
            return result;
        }
    }
}
